import axios from 'axios'

const baseURL = process.env.NODE_ENV === 'development' ? 'http://localhost:2006' : '真实URL'

const service = axios.create({
  baseURL,
  timeout: 5000
})

//请求拦截
service.interceptors.request.use(config => {
  config.headers = {
    'X-Token': 'sagasgasg'
  }
  return config
})

//响应拦截
service.interceptors.response.use(config => {
  if(config.status >= 200 && config.status < 300) {
    const res = config.data

    if(res.code === 200) {
      return res.data
    }
    return Promise.reject(res)
  }
  return Promise.reject(config)
})

export default service